package com.example.seckillprovider.controller;

import com.example.seckillprovider.mapper.GoodsMapper;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author likaiping
 * @createTime 2024/7/6 20:23
 */
@RestController
@AllArgsConstructor
public class SecKillController {

    private GoodsMapper goodsMapper;

    /**
     * 获取商品库存
     * @param gid
     * @return
     */
    @GetMapping("/getGoodsStock")
    public Integer getGoodsStock(@RequestParam("gid") Integer gid){
        System.out.println("进入seckill-provider的controller的getGoodsStock");
        System.out.println("gid:"+gid);
        return goodsMapper.getGoodsStock(gid);
    }

    /**
     * 设置商品库存
     * @param gid
     * @param stock
     * @return
     */
    @GetMapping("/setGoodsStock")
    public boolean setGoodsStock(@RequestParam("gid") Integer gid,@RequestParam("stock") Integer stock){
        return goodsMapper.setGoodsStock(gid,stock);
    }

    /**
     * 修改商品库存
     * @param gid
     * @param stock
     * @return
     */
    @GetMapping("/editGoodsStock")
    public boolean editGoodsStock(@RequestParam("gid") Integer gid,@RequestParam("stock") Integer stock){
        return goodsMapper.updateGoodsStock(gid,stock);
    }
}
